//
// Created by Tan Ke on 2023/11/19.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


char* firstPalindrome(char** words, int wordSize)
{
    for (int i = 0; i < wordSize; i ++) {
        char* word = words[i];
        int found = 0;

        for (int j = 0; j < strlen(word) / 2; j ++) {
            if (word[j] != word[strlen(word) - j - 1]) {
                found = -1;
                break;
            }
        }
        if (found == 0) {
            return word;
        }
    }
    return "";
}

int main(void)
{
    char** words1 = (char**)malloc(sizeof(char*) * 5);
    for (int i = 0; i < 5; i ++) {
        words1[i] = (char*)malloc(sizeof(char) * 24);
        memset(words1[i], 0, sizeof(char) * 24);
    }
    sprintf(words1[0], "abc");
    sprintf(words1[1], "car");
    sprintf(words1[2], "ada");
    sprintf(words1[3], "racecar");
    sprintf(words1[4], "cool");

    printf("%s\n", firstPalindrome((char**)words1, 5));
    return 0;
}